﻿using DX;
using DX.ViewModels;
using DX.Views;
using System.Collections.Generic;
using System.Linq;
using Tools.Plugins.Envs.Views;

namespace Tools.Plugins.Envs.ViewModels
{
    [ViewType(typeof(EnvForm))]
    public partial class EnvViewModel : ViewModel
    {
        public EnvViewModel()
        {
            Title = "用户环境变量";
        }
        [CommunityToolkit.Mvvm.ComponentModel.ObservableProperty]
        private IList<EnvInfo> _envs;

        [CommunityToolkit.Mvvm.Input.RelayCommand]
        private void Refresh()
        {
            var env = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Environment");
            var keys = env.GetValueNames().Select(n => new EnvInfo { Name = n, Value = env.GetValue(n)?.ToString() }).ToList();
            Envs =new System.Collections.ObjectModel.ObservableCollection<EnvInfo>(keys)  ;
        }
        protected override void OnAttach(IView view, IViewModel viewModel)
        {
            base.OnAttach(view, viewModel);
            Refresh();
        }

    }
}
